package selef.xiafan.dao;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import selef.xiafan.entity.user.User;

import java.util.List;

public interface UserDao extends JpaRepository<User,Long> {

    User findByUsername(String username);

    User findById(Integer id);

    void deleteByUsername(String username);

    void deleteById(Integer id);

    @Query(nativeQuery = true,value = "SELECT COUNT(*) FROM t_user")
    Long countAll();

    @Query(nativeQuery = true,value = "SELECT * FROM t_user WHERE is_sys=true LIMIT :page,:size")
    List<User> findAllNoQuery(@Param("page")Integer page, @Param("size")Integer size);

    @Query(nativeQuery = true,value = "SELECT * FROM t_user WHERE username LIKE CONCAT('%',:username,'%') AND is_sys=true LIMIT :page,:size")
    List<User> findAllByQuery(@Param("page")Integer page,@Param("size")Integer size, @Param("username") String username);
}
